package com.itboye.sunsunhome.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import android.content.Context;

public class SoLoadUtil {
	/**
	 * Created by mengh on 2016/1/6 006.
	 */

	    /*封装native方法，先加载so文件后调用native方法*/
	    public String getResult(Context context,String value){
//	        loadLibrary(context, "armeabi/libgetuiext (2).so");

	        loadLibrary(context, "armeabi/libgetuiext.so");
//	        loadLibrary(context, "armeabi/libiPN_API (2).so");
	        loadLibrary(context, "armeabi/libiPN_API.so");
//	        loadLibrary(context, "armeabi/libPPPP_API (2).so");
	        loadLibrary(context, "armeabi/libPPPP_API.so");
//	        loadLibrary(context, "armeabi-v7a/libgetuiext (2).so");
	        loadLibrary(context, "armeabi-v7a/libgetuiext.so");
//	        loadLibrary(context, "armeabi-v7a/libiPN_API (2).so");
	        loadLibrary(context, "armeabi-v7a/libiPN_API.so");
	        loadLibrary(context, "armeabi-v7a/libPPPP_API.so");
	        return getResult(value);
	    }

	    /*加载so文件*/
	    private void loadLibrary(Context context,String soName) {
	        try {
	            //获取文件输入流
	            InputStream inStream = context.getAssets().open(soName);
	            //获取文件输出流：目录是/data/data/app包名/app_lib/（该目录为app私有目录，具有执行权限）
	            File libsDir = context.getDir("libs", Context.MODE_PRIVATE);
	            String soFilePath=libsDir.getAbsolutePath() + "/"+soName;
	            FileOutputStream outStream = new FileOutputStream(soFilePath);
	            //使用两个流复制文件
	            FileUtil.copyFile(inStream,outStream);
	            //加载so文件
	            System.load(soFilePath);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }

	    public native String getResult(String value);

}
